<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h2>以字符串的方式访问对象属性</h2>
    <ul>
        <li>js提供了以字符串作为属性名的方式，来访问对象的属性。</li>
        <li>主要用于如果对象的属性名不是标准标识符的情况下。</li>
        <li>语法：对象名[字符串]</li>
    </ul>
    <script>
        let obj = {
            "my-friend": "胡正",
            name: "奉先",
        }
        
        console.log(obj["my-friend"]);

        let str = "name";
        console.log(obj[str]);
    </script>
</body>
</html>